/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2023-10-28
 * Time: 23:01
 */
public class Solution {
    // 二分查找
    public int minimumSize(int[] nums, int maxOperations) {
        int max = nums[0];
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            max = Math.max(max, nums[i]);
        }
        // 二分的范围就是 [1, max[i]]
        int left = 1;
        int right = max;
        while (left < right) {
            int mid = ((right-left) >> 1) + left;
            // 记录如果 最大值 变为 mid 时需要操作的次数
            int count = 0;
            for (int i = 0; i < len; i++) {
                count += (nums[i] - 1) / mid;
            }
            // 操作次数过多, 那么 就让最大值变大
            if (count > maxOperations) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return left;
    }
}